package com.hmdp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmdp.dto.Result;
import com.hmdp.entity.Sign;
import com.hmdp.mapper.SignMapper;
import com.hmdp.service.ISignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class SignServiceImpl extends ServiceImpl<SignMapper, Sign> implements ISignService {
    @Resource
    private SignMapper signMapper;

    @Override
    public Result queryById(Long id) {
        QueryWrapper<Sign> infoQueryWrapper = new QueryWrapper<>();
        infoQueryWrapper.eq("user_id", id);
        Sign existingRates = signMapper.selectOne(infoQueryWrapper);
        //更新level
        if(existingRates.getSignCounts()!=null&&existingRates.getSignCounts()>10){
            existingRates.setLevel((int) (existingRates.getSignCounts()/10)+1);
        }
        signMapper.updateById(existingRates);

        return Result.ok(existingRates);
    }
}
